package projeto1;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Window;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;

import java.awt.Font;

import javax.swing.JTextField;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Color;

import javax.swing.ImageIcon;







import java.awt.BorderLayout;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;

import java.awt.Font;

import javax.swing.JTextField;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Color;

import javax.swing.ImageIcon;
import javax.swing.JPasswordField;
import java.awt.SystemColor;


public class LoginAdm extends JDialog {
	private JTextField tfusuario;
	private JPasswordField passwordField;
	InserirNovoLogin CliControl = new InserirNovoLogin();
	
	
	/**
	 * Launch the application.
	 */
	
	public static void main(String[] args) {
		
		try {
			LoginAdm dialog = new LoginAdm();
			dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
			dialog.setVisible(true);
		} catch (Exception e) {
			
			e.printStackTrace();
		}
		
	}
	
	/**
	 * Create the dialog.
	 */
	public LoginAdm() {
		setTitle("TRANSF\u00C1CIL-Login Administrador");
		setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
		getContentPane().setBackground(SystemColor.menu);
		setBounds(100, 100, 670, 400);
		getContentPane().setLayout(null);
		{
			JLabel lblNewLabel = new JLabel("\u00C1rea restrita. Insira seus dados de ADMINISTRADOR para continuar:");
			lblNewLabel.setForeground(Color.BLACK);
			lblNewLabel.setFont(new Font("Arial", Font.BOLD, 15));
			lblNewLabel.setBounds(17, 11, 528, 18);
			getContentPane().add(lblNewLabel);
		}
		{
			JLabel lblLogin = new JLabel("Login");
			lblLogin.setForeground(Color.BLACK);
			lblLogin.setFont(new Font("Arial", Font.PLAIN, 15));
			lblLogin.setBounds(124, 70, 35, 18);
			getContentPane().add(lblLogin);
		}
		{
			tfusuario = new JTextField();
			tfusuario.setBounds(194, 70, 302, 20);
			getContentPane().add(tfusuario);
			tfusuario.setColumns(10);
			
		}
		{
			JLabel lblSenha = new JLabel("Senha");
			lblSenha.setFont(new Font("Arial", Font.PLAIN, 15));
			lblSenha.setBounds(117, 113, 42, 18);
			getContentPane().add(lblSenha);
		}
		{
			JButton btnOk = new JButton("CONFIRMA");
			btnOk.setToolTipText("Validar Login");
	
			btnOk.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					String usuario = tfusuario.getText().toString();
					tfusuario.setText("");
					@SuppressWarnings("deprecation")
					String senha = passwordField.getText().toString();
					
					Conexao bd = new Conexao();
					bd.BDLogar(usuario, senha);
					if(bd.valida){
						Cadastro cad = new Cadastro();
						cad.setVisible(true);
						LoginAdm.this.dispose(); 
					
						
						
					}
					else{
						JOptionPane.showMessageDialog(null, "ERRO");
//						ErroLogin erro = new ErroLogin();				
					}
					bd.valida=false;
					
					
				}
			});
			btnOk.setFont(new Font("Arial", Font.PLAIN, 11));
			btnOk.setBounds(446, 158, 116, 27);
			getContentPane().add(btnOk);
			
		}
		
		JButton btnNewButton = new JButton("ANTERIOR");
		btnNewButton.setToolTipText("Retornar para TELA INICIAL");
		btnNewButton.setFont(new Font("Arial", Font.PLAIN, 11));
		btnNewButton.setBounds(10, 327, 116, 24);
		
		btnNewButton.addActionListener(new ActionListener() {
			//Chama tela inicial(main)
			public void actionPerformed(ActionEvent e) {
				Main TelaInicio = new Main();
				TelaInicio.setVisible(true);
				LoginAdm.this.dispose(); 
			}
		});
		
		getContentPane().add(btnNewButton);
		{
			passwordField = new JPasswordField();
			passwordField.setBounds(194, 113, 303, 20);
			getContentPane().add(passwordField);
		}
		{
			JButton btnNewButton_1 = new JButton("ALTERAR SENHA");
			btnNewButton_1.setToolTipText("Para Alterar Senha:Digite o login e a senha no campo acima ");
			btnNewButton_1.setFont(new Font("Arial", Font.PLAIN, 11));
			btnNewButton_1.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					String senha = passwordField.getText().toString();
					String senha2= JOptionPane.showInputDialog(null,"Digite Sua nova senha :  ");
					CliControl.InsereDados2(senha2, senha);
					
					
					
				}
			});
			btnNewButton_1.setBounds(487, 329, 157, 23);
			
			
			
			
			getContentPane().add(btnNewButton_1);
		}
		{
			JLabel lblParaAlterarA = new JLabel("Para alterar a  sua senha Digite seu usu\u00E1rio e senha no campo acima e clique aqui:");
			lblParaAlterarA.setFont(new Font("Arial", Font.PLAIN, 10));
			lblParaAlterarA.setBounds(251, 304, 513, 14);
			getContentPane().add(lblParaAlterarA);
		}
		{
			JButton btnLimpar = new JButton("LIMPAR");
			btnLimpar.setToolTipText("Limpar Campo Login/Senha");
			btnLimpar.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					
					tfusuario.setText("");
					passwordField.setText("");
					
					
					
					
				}
			});
			btnLimpar.setFont(new Font("Arial", Font.PLAIN, 11));
			btnLimpar.setBounds(218, 160, 107, 23);
			getContentPane().add(btnLimpar);
		}
	}
	
}
